import datetime
from pymongo import MongoClient


countries = []

for line in open("config/countries.txt"):
    line = line.strip().decode("utf-8")
    countries.append(line)

client = MongoClient()
db = client.leaders

leader = u"xjp"
last_report = None

for report in db[leader].find({u"input_date": {u"$lt": datetime.datetime(2034, 3, 1)}}):
    for country in countries:
        if country in report[u"title"]:
            if report[u"title"] == last_report:
                continue

            print report[u"input_date"].strftime("%Y%m%d"), ',',
            print report[u"title"].encode("utf-8")

            last_report = report[u"title"]
